<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>贷款信息管理</title> 
<#include '/frame/version.html'> 
<#include '/frame/manage/include_css.html'> 
<#include '/frame/manage/include_js.html'> 
<script type="text/javascript" src="${basePath}/js/My97DatePicker/WdatePicker.js"></script>
<#include '/frame/taglib.html'>
</head>
<body id="nv_member" class="pg_CURMODULE">
	<#assign current='menu_loan_info'>
	<div id="wp" class="wp">
		<#include "/include/header.html"/>
		<div class="contentmanage">
			<div class="developer">
				<div class="tableContent">
					<#include "/include/left.html"/> 
					<#include "/include/wxtop.html"/>
					<div class="content">
					<div class="cLineB">
				        <h4 class="left">
				        	贷款信息管理
				        </h4>
				        <div class="clr">
				        </div>
						<div class="msgWrap">
						<div class="cLine">
							<div class="pageNavigator left">
								<form id="export_form_pagination" action="${basePath}/admin/loan/ex" method="post" target="_self">
								<a class="btnGrayS" href='${basePath}/admin/loan/im/0'>
                                    <img class="vm" src="${basePath}/images/import-16.png">&nbsp;&nbsp;导入贷款信息
                                </a>
                                <a class="btnGrayS" href='${basePath}/admin/loan/im/1'>
                                    <img class="vm" src="${basePath}/images/import-16.png">&nbsp;&nbsp;导入贷款处理结果
                                </a>
								<select name="flags">
									<option value="1">导出全部</option>
									<option value="0">导出当前页</option>
								</select>
								<input type="hidden" name="currentPage" value="${page.currentPage}" />
								<a class="btnGrayS" href='javascript:void(0)' onclick="doExport(this)">
									<img class="vm" height="20" width="20" src="${basePath}/images/export-32.png">&nbsp;&nbsp;导出客户信息
								</a>
								<a class="btnGrayS" href='javascript:void(0)' onclick="doExport2(this)">
									<img class="vm" height="20" width="20" src="${basePath}/images/export-32.png">&nbsp;&nbsp;导出贷款凭证
								</a>
								</form>
	               			</div>
							
						<div class="searchbar left">
					        <form id="searchForm" action="${basePath}/admin/loan/index" method="post">
					       <#if orgLevel!=3>
					          网点：
					        <input type="text" id="input_keyword" value="" placeholder="请输入机构名称检索" style="border: 1px solid #ccc;height: 23px;"/>
							<input type="button" value="搜索" class="btnGreen" id="input_search"/>
							<select class="input_width_200" name="loanOrgCode" id="loanOrgCode">
									<#if orgInfo??>
									  <option value='${orgInfo.orgCode}'>${orgInfo.orgName}</option>
									</#if>
							</select>
					       </#if>
					        是否关注：
					           <select name="isConcern" >
					              <option value="">请选择</option>
					              <option value="0" <#if bean.isConcern?exists && bean.isConcern==0>selected</#if>>是</option>
					              <option value="1" <#if bean.isConcern?exists && bean.isConcern==1>selected</#if>>否</option>
					           </select>
					        是否绑定：
					           <select name="isBinding" >
					              <option value="">请选择</option>
					              <option value="0" <#if bean.isBinding?exists && bean.isBinding==0>selected</#if>>否</option>
					              <option value="1" <#if bean.isBinding?exists && bean.isBinding==1>selected</#if>>是</option>
					           </select>
					           是否已交凭证：
					           <select name="isCheck" >
					              <option value="">请选择</option>
					              <option value="0" <#if bean.isCheck?exists && bean.isCheck==0>selected</#if>>否</option>
					              <option value="1" <#if bean.isCheck?exists && bean.isCheck==1>selected</#if>>是</option>
					           </select>
					          <br/>    <br/> 
					       是否结清：
					           <select name="isClear" >
					              <option value="">请选择</option>
					              <option value="0" <#if  bean.isClear?? && bean.isClear=='0'>selected</#if>>否</option>
					              <option value="1" <#if  bean.isClear?? && bean.isClear=='1'>selected</#if>>是</option>
					           </select> 
					        凭证审核状态:
					           <select name="isCheckConform" >
					              <option value="">请选择</option>
					              <option value="0" <#if bean.isCheckConform?exists && bean.isCheckConform==0>selected</#if>>待审核</option>
					              <option value="1" <#if bean.isCheckConform?exists && bean.isCheckConform==1>selected</#if>>通过</option>
					              <option value="2" <#if bean.isCheckConform?exists && bean.isCheckConform==2>selected</#if>>不通过</option>
					           </select>
					         放款日期:
					    <input type="text" class="px input_width_200" id="loanDate" <#if bean.loanDate?exists>value="${bean.loanDate?date}"</#if> name="loanDate" placeholder="放款日期"
					 	onClick="WdatePicker({dateFmt:'yyyy-MM-dd',readOnly:true})"/>
					 	借款到期日:
					    <input type="text" class="px input_width_200" id="loanDate" <#if bean.debtDueDate?exists>value="${bean.debtDueDate?date}"</#if> name="debtDueDate" placeholder="借款到期日"
					 	onClick="WdatePicker({dateFmt:'yyyy-MM-dd',readOnly:true})"/><br/><br/>
					 	借款结清日期:
					    <input type="text" class="px input_width_200" id="loanDate" <#if bean.loanCleanDate?exists>value="${bean.loanCleanDate?date}"</#if> name="loanCleanDate" placeholder="贷款清算日期"
					 	onClick="WdatePicker({dateFmt:'yyyy-MM-dd',readOnly:true})"/>
					          姓名:<input  type="text" placeholder="输入客户名称" class="px" name="custName" value="${bean.custName?default('')}"/>
					          身份证号:<input  type="text" placeholder="请输 入身份证号" class="px" name="custIdNum" value="${bean.custIdNum?default('')}"/>
					         手机号:<input type="text"  placeholder="请输入手机号" class="px" name="custPhone" value="${bean.custPhone?default('')}"/>
						<br/><br/>
					       标签:  <select name="flag">
					       		<option value="" >请选择</option>
							    <#if tags??>
							    	<#list tags as wxTag>
							    		 <option value="${wxTag.tagId}">${wxTag.tagName}</option>
							    	</#list>
							    </#if>
					           </select>
					           <input type="button" title="搜索" class="btnGreen" value="搜索" onclick="searchOrExcel(1)"/>
					        </form>
					    </div>
					    <div class="pageNavigator left">
					    选择标签:<select name="isFlag" id="makeTag">
							    <#if tags??>
							    	<option value="" >请选择</option>
							    	<#list tags as wxTag>
							    		 <option value="${wxTag.tagId}" >${wxTag.tagName}</option>
							    	</#list>
							    </#if>
					           </select>
					           <input type="button" title="批量打标签" class="btnGreen" value="批量打标" onclick="makeTag()"/>
					           <input type="button" title="批量删除标签" class="btnGreen" value="批量删除标签" onclick="removeTag()"/>
						</div>
					    <div style="width:100%;overflow:auto;min-height: 400px;padding-top: 5px;">
							<table class="ListProduct Shallow_border_color" border="0" cellSpacing="0" cellPadding="0" width="150%;" style="width:150%">
								<thead>
									<tr>
										<th><input id="checkAll" type="checkbox" /></th>
										<th>序号</th>
										<th>是否<br/>绑定 </th>
										<th>是否<br/>关注 </th>
										<th>凭证是否<br/>已交</th>
				                        <th>凭证是否<br/>符合</th>
				                        <th>是否<br/>结清</th>
										<th>客户姓名 </th>
                         				<th>身份证号 </th>
				                        <th>手机号</th>
				                        <th>分行</th>
				                        <th>支行</th>
				                        <th>放款日期</th>
				                        <th>借款到期日</th>
				                        <th>借款结清日期</th>
				                        <th>标签 </th>
				                        <th>操作 </th>
									</tr>
								</thead>
								<tbody>
									<#if page?exists> 
									<#list page.recordList as beans>
									<tr>
										<td>
											<input name="subBox" class="emp_id" type="checkbox" value="${beans.loanId}"/>
											<input name="openId" class="selected" type="hidden" value="${beans.openid}"/>
											<input name="flagTag" class="selected2" type="hidden" value="${beans.flag}"/>
										</td>
										<td valign="middle" align="center">${page.pernum*(page.currentPage-1)+beans_index+1}</td>
										
										<td>
				                            <#if beans.isBinding==1>是
					                            <#else>否
				                            </#if>
				                        </td>
				                        <td>
				                            <#if beans.openid==1 || !beans.openid??>否
					                            <#else>是
				                            </#if>
				                        </td>
				                        <td>
				                        	<#if beans.isCheck==0>否
					                            <#elseif beans.isCheck==1>是
				                            </#if>
				                         </td>
				                         <td>
				                        	<#if beans.isCheckConform==0>待审核
					                            <#elseif beans.isCheckConform==1>已通过
					                            <#elseif beans.isCheckConform==2>不通过
				                            </#if>
				                         </td>
				                         <td>
				                        	<#if !beans.loanCleanDate??>
				                        			否
					                           <#else>是
				                            </#if>
				                         </td>
										<td>${beans.custName?default('')}</td>
				                        <td>${beans.custIdNum?default('')}</td>
				                        <td>${beans.custPhone?default('')}</td>
				                        <td>${beans.orgBranch?default('')}</td>
				                        <td>${beans.subBranch?default('')}</td>
				                        <td><#if beans.loanDate??>${beans.loanDate?date}</#if></td>
				                        <td><#if beans.debtDueDate??>${beans.debtDueDate?date}</#if></td>
				                        <td><#if beans.loanCleanDate??>${beans.loanCleanDate?date}</#if></td>
				                         <td>
				                         	<#if beans.flag?? && beans.flag!=''>
				                         		<#list beans.flag?split(",") as tagTab>
													   <#list tags as tabLib>
													   		<#if tagTab==tabLib.tagId>
													   			${tabLib.tagName}&nbsp;&nbsp;
													   		</#if>
													   </#list>
												</#list>
				                         	</#if>
				                         </td>
										<td class="norightborder">
										<a href="javascript:void(0);"  onclick="certificate('${beans.loanId?default(0)}');">用途凭证</a>
										<a href="javascript:void(0);"  onclick="detailInfo('${beans.loanId?default(0)}');">详情</a>
										</td>
									</tr>
									</#list> 
									</#if>
								</tbody>
							</table>
							</div>
							<#include "/include/form_pagination.html"/>
						<#include "/include/simple_page_js.html"/>
						</div>
					</div>
					<div class="clr"></div>
				</div>
			</div>
		</div>
		<!--底部-->
	</div>
	<!--ad start-->
	<!--ad end-->
	</div>
	</div>
	</div>
	<#include "/include/footer.html"/>
	<script>
	
	$(function(){
		$("#input_search").on("click",function(){
			var $this = $(this),$keyword = $this.prev();
			var keyword = $keyword.val();
			if(utils.isEmpty(keyword)){
				stem.tip("请输入关键词", $keyword.get(0));
				return;
			}else{
				$.post("${basePath}/admin/loan/ins",{keyword:keyword},function(data){
					if(data!=null&&data.length>0){
						var options = "";
						for(var i=0;i<data.length;i++){
							options += "<option value='"+data[i].code+"'>"+data[i].name+"</option>";
						}
						$("#loanOrgCode").html(options);
					}else{
						stem.msg("无符合的机构信息！");
					}
				},"json");
			}
		});
	});
	
	
	
	function searchOrExcel(mark){
		$("#searchForm").submit();
	}
	
	function detailInfo(id){
		if(0!=id){
			location.href='${basePath}/admin/loan/detailInfo'+id;
		}else{
			stem.warn("无效数据！");
		}
	}
	
	function certificate(loanId){
		if(0!=loanId){
			window.location.href='${basePath}/admin/loan/certificate/'+loanId;
		}else{
			stem.warn("无效数据！");
		}
	}
	
	function makeTag(){
	var tag=$('#makeTag option:selected') .val();
	var flag=true;
	if(tag==''){
		stem.info("请选择标签");
		return false;
	}
	var $box = $(".emp_id:checked");
	var $box2 = $(".emp_id:checked").siblings(".selected");
	var $box3 = $(".emp_id:checked").siblings(".selected2");
	if($box.length==0){
		stem.info("请至少选中一个");
		return false;
	}
	var ids = new Array();
	var openIds=new Array();
	$box.each(function(){
		ids.push(this.value);
	});
	$box2.each(function(){
		openIds.push(this.value);
	});
	$box3.each(function(){
		var split= new Array();
		split=this.value.split(",");
		if($.inArray(tag,split)!=-1){
			stem.info("有重复打标数据，请先筛选");
			flag=false;
		}
	});
	console.log(ids);
	if(flag){
	stem.confirm("确定要打标签吗？","确认信息",function(){
		$.ajax({
            cache : false,
            type: "POST",
            url: "${basePath}/admin/loan/makeTag",
            data: {"ids":ids.join(),"tag":tag,"openIds":openIds.join()},
            async : false,
            dataType: "text",
            error : function(request) {
                stem.msg("系统繁忙，请重试！");
                return false;
            },
            success: function(data){
            	if(data=="success"){
            		stem.msg("打标签成功", function(){
                  		location.href="${basePath}/admin/loan/index"
            		});
            	}else{
            		stem.msg("打标签失败，请注意是否关注", function(){
                  		location.href="${basePath}/admin/loan/index"
            		});
            	}
            }
         });
	});
	}
}

function removeTag(){
	var tag=$('#makeTag option:selected') .val();
	var flag=true;
	if(tag==''){
		stem.info("请选择标签");
		return false;
	}
	var $box = $(".emp_id:checked");
	var $box2 = $(".emp_id:checked").siblings(".selected");
	var $box3 = $(".emp_id:checked").siblings(".selected2");
	if($box.length==0){
		stem.info("请至少选中一个");
		return false;
	}
	var ids = new Array();
	var openIds=new Array();
	$box.each(function(){
		ids.push(this.value);
	});
	$box2.each(function(){
		openIds.push(this.value);
	});
	$box3.each(function(){
		var split=this.value.split(",");
		if($.inArray(tag,split)==-1){
			stem.info("有数据无此标签，请先筛选");
			flag=false;
		}
	});
	console.log(ids);
	if(flag){
	stem.confirm("确定要移除标签吗？","确认信息",function(){
		$.ajax({
            cache : false,
            type: "POST",
            url: "${basePath}/admin/loan/removeTag",
            data: {"ids":ids.join(),"tag":tag,"openIds":openIds.join()},
            async : false,
            dataType: "text",
            error : function(request) {
                stem.msg("系统繁忙，请重试！");
                return false;
            },
            success: function(data){
            	if(data=="success"){
            		stem.msg("取消标签成功", function(){
                  		location.href="${basePath}/admin/loan/index"
            		});
            	}
            	else{
            		stem.msg("取消标签失败，请注意是否关注", function(){
                  		location.href="${basePath}/admin/loan/index"
            		});
            	}
            }
         });
	});
	}
}



function doExport(that) {
	location.href="${basePath}/admin/loan/ex?"+$("#export_form_pagination").serialize()+"&"+$("#searchForm").serialize();
}

function doExport2(that) {
	location.href="${basePath}/admin/loan/ex/credit?"+$("#export_form_pagination").serialize()+"&"+$("#searchForm").serialize();
}


$(function() {
    $("#checkAll").click(function() {
         $('input[name="subBox"]').attr("checked",this.checked); 
     });
     var $subBox = $("input[name='subBox']");
     $subBox.click(function(){
         $("#checkAll").attr("checked",$subBox.length == $("input[name='subBox']:checked").length ? true : false);
     });
 });
	</script>
</body>
</html>